package site.weiyikai.eventdriven.core;

import lombok.Data;

import java.util.function.Predicate;


/*
 * 订阅器key
 *
 * @author 程序员小魏
 * 创建时间: 2023/11/03
 */
@Data
public class SubscriptionKey {

    private final String channel;
    private final Predicate eventMatcher;

    SubscriptionKey(String channel, Predicate eventMatcher) {
        this.channel = channel;
        this.eventMatcher = eventMatcher;
    }

    public boolean matches(String sentToChannel, Object event) {
        if (this.channel != null && sentToChannel != null && this.eventMatcher != null) {
            return this.channel.equalsIgnoreCase(sentToChannel) && this.eventMatcher.test(event);
        } else {
            return false;
        }
    }
}